﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter2.Section5
{
    public class Example05
    {
        public Example05()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double[], double[]> f
                = new V.Function.ToLastType<double[], double[]>(funcf);
            V.Function.ToLastType<double[], double[]> g
                = new V.Function.ToLastType<double[], double[]>(funcg);

            double[] x0 = { 0.0, 0.0 };

            V.ChainRule obj = new V.ChainRule(f, g, x0);
            obj.Compute();

            result += obj.Result[0, 0].ToString() + "    ";
            result += obj.Result[0, 1].ToString() + "\r\n";
            result += obj.Result[1, 0].ToString() + "    ";
            result += obj.Result[1, 1].ToString() + "\r\n";
        }
        private double[] funcf(double[] u)
        {
            double[] r = new double[2];
            r[0] = Math.Cos(u[1]) + u[0]*u[0];
            r[1] = Math.Exp(u[0]+u[1]);
            return r;
        }
        private double[] funcg(double[] x)
        {
            double[] r = new double[2];
            r[0] = Math.Exp(x[0] * x[0]);
            r[1] = x[0] - Math.Sin(x[1]);
            return r;
        }
    }
}
/*
0    0
2.71828182845936    -2.71828182845936
*/
